/*
	This file is part of the JKTest
    Copyright (C) 2008 Royce Y. Feng <ryfeng@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License version 3
    as published by the Free Software Foundation. You may not use, modify
    or distribute this program under any other version of the
    GNU Affero General Public License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package JKAboutMe;

import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.BorderFactory;
import javax.swing.SwingUtilities;
import javax.swing.BoxLayout;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.awt.GridLayout;

import jktest.JKHyperLabel;

/**
 * 
 * AboutMe class that tells a little about JKTest
 * 
 * @author Royce Feng
 */
public class AboutMeGUI {

    private JDialog frame = new JDialog();
    private JPanel panel = new JPanel();
    private JPanel infoPanel = new JPanel( new GridLayout(3,2) );
    private JPanel DLInfoPanel = new JPanel( new GridLayout(2,2) );

    private class KeyStalker implements KeyListener {
        public void keyReleased( KeyEvent e ) {}
        public void keyPressed( KeyEvent e ) {
            switch ( e.getKeyCode() ) {
                case 112: //F1
                case 27: // ESC
                    frame.setVisible(!frame.isVisible());
                    break;
                default:
                    break;
            }
        }
        public void keyTyped( KeyEvent e ) {}
    }
    
    /**
     * 
     * Main Constructor. Creates a few JLabels and panels about the program.
     * 
     */
    public AboutMeGUI() {
        frame.setTitle("About Me");
        frame.addKeyListener(new KeyStalker());
        frame.setContentPane(panel);
        frame.setResizable(false );
        frame.setDefaultCloseOperation ( JDialog.HIDE_ON_CLOSE );
        panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
        infoPanel.setBorder( BorderFactory.createTitledBorder("Information:") );
        infoPanel.add( new JLabel("Author: ") );
        infoPanel.add( new JLabel("Royce Y. Feng") );
        infoPanel.add( new JLabel("Language Programmed in: ") );
        infoPanel.add( new JLabel("Java") );
        infoPanel.add( new JLabel("Project Start Date: ") );
        infoPanel.add( new JLabel("2008-08-15") );
        panel.add(infoPanel);
        panel.add( DLInfoPanel );
        DLInfoPanel.setBorder( BorderFactory.createTitledBorder("Source:") );
        DLInfoPanel.add( new JLabel("SVN: ") );
        DLInfoPanel.add( new JKHyperLabel("http://svn.assembla.com/svn/JKTest") );
        DLInfoPanel.add( new JLabel("TRAC: ") );
        DLInfoPanel.add( new JKHyperLabel("http://trac.assembla.com/JKTest/timeline") );
        frame.pack();
    }

    /**
     *
     * Swaps the current visibility (if true, then false, if false then true)
     *
     */
    public void toggleVisible() {
        frame.setVisible(!frame.isVisible());
    }

    /**
     *
     * Reskins and packs the GUI
     *
     */
    public void pack() {
        SwingUtilities.updateComponentTreeUI(frame);
        frame.pack();
    }
    
}
